//
//  ZJJLViewController.m
//  Estate
//
//  Created by heyong on 16/5/26.
//  Copyright © 2016年 ttsx. All rights reserved.
//
#define LIST_W DEF_WIDTH(self.view)-70

#define DIC_EXPANDED @"expanded" //是否是展开 0收缩 1展开
#define DIC_ARARRY @"array"
#define DIC_TITILESTRING @"title"
#define CELL_HEIGHT 46.0f
#import "RJTableCell.h"
#import "JLJLTableCell.h"
#import "ZJJLViewController.h"
#import "JLAddJLViewController.h"
#import "JJTYPZViewController.h"

@interface ZJJLViewController ()
{
    UIButton *_rightBtn;
}
@end

@implementation ZJJLViewController

-(NSMutableArray *)dataArray{
    if(_dataArray==nil){
        _dataArray=[NSMutableArray array];
    }
    return _dataArray;
}

-(NSMutableArray *)seleceId{
    if(_seleceId==nil){
        _seleceId=[NSMutableArray array];
    }
    return _seleceId;
}

//懒加载
-(PeopleListView *)listView{
    if(_listView==nil){
        _listView=[[PeopleListView alloc]initWithFrame:CGRectMake(DEF_SCREEN_WIDTH,0,DEF_SCREEN_WIDTH*0.85, DEF_SCREEN_HEIGHT)];
    }
    return _listView;
}

//btn数据源
-(NSMutableArray *)btnArray{
    if(_btnArray==nil){
        _btnArray=[NSMutableArray array];
    }
    return _btnArray;
}

-(NSMutableArray *)seleceArr{
    if(_seleceArr==nil){
        _seleceArr=[NSMutableArray array];
    }
    return _seleceArr;
}

-(UITableView *)tableView{
    if(_tableView==nil){
        _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, (DEF_SCREEN_HEIGHT-64-49-55))];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        _tableView.tableFooterView=[[UIView alloc]initWithFrame:CGRectZero];
        _tableView.backgroundColor=[UIColor colorWithRed:0.97 green:0.97 blue:0.97 alpha:1.00];
        [_tableView registerNib:[UINib nibWithNibName:@"RJTableCell" bundle:nil] forCellReuseIdentifier:@"RJCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"JLJLTableCell" bundle:nil] forCellReuseIdentifier:@"JLJLCell"];
        
    }
    return _tableView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *myWindow=[UIApplication sharedApplication].keyWindow;
        [myWindow addSubview:self.listView];
    });
    
    self.listView.collectionView.delegate=self;
    self.listView.collectionView.dataSource=self;
    [self.listView.collectionView registerClass:[btnCollCell class] forCellWithReuseIdentifier:@"Cell"];
    //注册头部
    [self.listView.collectionView registerClass:[SXheadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headView"];
    //添加事件
    [self.listView.cancelBtn addTarget:self action:@selector(clickCan) forControlEvents:UIControlEventTouchUpInside];
    [self.listView.sureBtn addTarget:self action:@selector(clickSure) forControlEvents:UIControlEventTouchUpInside];
    
    self.view.backgroundColor=[UIColor colorWithRed:0.97 green:0.97 blue:0.97 alpha:1.00];
    //创建添加按钮 和弹出按钮
    [self createView1];
    
    //侧边栏所有数据
    self.btnArray=[LSUtility queryUserByPro:PROID];
    
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
    [self initDataSource];
    [center addObserver:self selector:@selector(refresh:) name:@"Refresh_zj_jl" object:nil];
}

- (void)refresh:(id)sender{
    [self.dataArray removeAllObjects];
    [self initDataSource];
    [self.tableView reloadData];
}

- (void)createView1{
    //创建添加btn
    self.addBtn=[[UIButton alloc]initWithFrame:CGRECTS(260, 360, 100, 100)];
    [_addBtn setImage:[UIImage imageNamed:@"add_2"] forState:UIControlStateNormal];
    _addBtn.tag=100;
    [self.view addSubview:_addBtn];
    
    [_addBtn addTarget:self action:@selector(addmethold:) forControlEvents:UIControlEventTouchUpInside];
    
    //弹出选择人物视图
    _rightBtn=[[UIButton alloc]initWithFrame:CGRECTS(DEF_SCREEN_WIDTH-70, 30, 70, 30)];
    _rightBtn.tag=101;
    _rightBtn.backgroundColor=[UIColor colorWithRed:0.78 green:0.26 blue:0.09 alpha:1.00];
    [_rightBtn setTitle:@"人员选择" forState:UIControlStateNormal];
    _rightBtn.titleLabel.font=[UIFont systemFontOfSize:13.];
    [_rightBtn addTarget:self action:@selector(addmethold:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_rightBtn];
    
}

#pragma mark-添加按钮
- (void)addmethold:(UIButton *)sender{
    if(sender.tag==100){
        JLAddJLViewController *addCtr=[[JLAddJLViewController alloc]init];
        
        addCtr.isEdit=YES;
        
        addCtr.flag=@"add";
        
        [self.navigationController pushViewController:addCtr animated:YES];
        
    }else{
        
        [UIView animateWithDuration:0.4 animations:^{
            _listView.frame =CGRectMake(DEF_SCREEN_WIDTH*0.15, 0, DEF_SCREEN_WIDTH*0.85, DEF_HEIGHT(self.view));
        }];
        
    }
}

//初始化数据
- (void)initDataSource
{
    FMDatabase *db=[FMDatabase databaseWithPath:DEF_DB_DATABASEPATH];
    [db open];
    
    FMResultSet *result;
    if(self.seleceArr.count>0){
        //条件查询的id
        self.seleceId=[LSUtility getuserNameByUserID:self.seleceArr];
        //转化为sql条件
        NSString *conditions=[LSUtility dictionaryToJson_2:self.seleceId];
        NSMutableString *muCon=[LSUtility SymbolConversion:conditions];
        result=[db executeQuery:
                SQL_WORKREDIARY_SELECT_ZJ_CON(PROID,muCon)];
    }else{
        result=[db executeQuery:
                SQL_WORKREDIARY_SELECT_ZJ(PROID)];
    }
    
    NSMutableDictionary *dic;
    
    while ([result next]) {
        //查询到 年
        NSString* year= [result stringForColumn:@"year"];
        //查询到月
        NSString *month =[LSUtility deletaeZero:[result stringForColumn:@"month"]] ;
        //查询到日
        NSString *day =[LSUtility deletaeZero:[result stringForColumn:@"day"]] ;
        
        //展开页查询条件
        NSString *condition=[result stringForColumn:@"date(CREATE_TIME)"];
        
        /*
         * 根据日期查询展开的数据
         */
        
        //条件查询的id
        self.seleceId=[LSUtility getuserNameByUserID:self.seleceArr];
        //转化为sql条件
        NSString *conditions=[LSUtility dictionaryToJson_2:self.seleceId];
        NSMutableString *muCon=[LSUtility SymbolConversion:conditions];
        NSString *sqlStr;
        if(self.seleceArr.count>0){
            sqlStr=[NSString stringWithFormat:@" SELECT time(CREATE_TIME) as time ,record_user,id,record_title,RECORD_TYPE,extend_info,record_info,RECORDONTENT,create_time FROM WORK_RECORD WHERE RECORD_TYPE not in('RECORD_05','RECORD_06')  AND date(CREATE_TIME) = '%@'  AND PRO_ID = '%@' AND RECORD_USER IN %@  ORDER BY CREATE_TIME desc",
                    condition,PROID,muCon];
        }else{
           sqlStr=[NSString stringWithFormat:@" SELECT time(CREATE_TIME) as time ,record_user,id,record_title,RECORD_TYPE,extend_info,record_info,RECORDONTENT,create_time FROM WORK_RECORD WHERE RECORD_TYPE not in('RECORD_05','RECORD_06')  AND  date(CREATE_TIME) = '%@'  AND PRO_ID = '%@'  ORDER BY CREATE_TIME desc",
                              condition,
                              DEF_PERSISTENT_GET_OBJECT(@"proid")];
        }
        
        FMResultSet *results=[db executeQuery:sqlStr];
        
//  //查询到记录
        NSMutableArray *DetailArr=[NSMutableArray array];
//
        while ([results next]) {
            //id
            NSString *ids=[results stringForColumn:@"ID"];
        
            //标题
            
            NSString *title=@"无";
            //类型
            NSString *type=[results stringForColumn:@"RECORD_TYPE"];
            title=[results stringForColumn:@"record_title"];

            //旁站标题显示标题
//            if([type isEqualToString:@"RECORD_02_01"]||[type isEqualToString:@"RECORD_02_02"]||[type isEqualToString:@"RECORD_02_03"]||[type isEqualToString:@"RECORD_02_04"]||[type isEqualToString:@"RECORD_02_05"]){
//                title=[results stringForColumn:@"record_title"];
//
//                //记录 内容显示成标题
//            }else{
//                title=[results stringForColumn:@"RECORDONTENT"];
//            }
            
            //内容

            //时间
            NSString *time=[results stringForColumn:@"time"];
            
            //位置
            NSString *address=@"";
            if([type isEqualToString:@"RECORD_03"]||[type isEqualToString:@"RECORD_04"]||[type isEqualToString:@"RECORD_01"])
            {
                NSString *addJson=[results stringForColumn:@"extend_info"];
                NSDictionary *dic=[LSUtility dictionaryWithJsonString:addJson];
                address=[dic objectForKey:@"address"];
            }else{
                NSString *addJson=[results stringForColumn:@"record_info"];
                NSDictionary *dic=[LSUtility dictionaryWithJsonString:addJson];
                address=[dic objectForKey:@"locationInfo"];
            }
            
            //记录人
            NSString *logUserId=[results stringForColumn:@"record_user"];
            NSString *recordName=[LSUtility getuserIdByUserName:logUserId][@"REAL_NAME"];
            //创建时间
            NSString *times=[results stringForColumn:@"create_time"];
            
            NSDictionary *dict=@{@"id":ids,
                                 @"title":title,
                                 @"time":time,
                                 @"address":DEFISNUL(address),
                                 @"recordId":logUserId,
                                 @"recordName":DEFISNUL(recordName),
                                 @"type":type,
                                 @"times":times};
            
            [DetailArr addObject:dict];
            
        }

        // 查询到数量
        NSString *count=[result stringForColumn:@"count"];
        // 拼接成标题
        NSString *tiemAndCount=[NSString stringWithFormat:@"%@年%@月%@日(%@条)",year,month,day,count];
        // 创建一个字典 包含数组，分组名，是否展开的标示
        dic=[[NSMutableDictionary alloc] initWithObjectsAndKeys:DetailArr,DIC_ARARRY,tiemAndCount,DIC_TITILESTRING,[NSNumber numberWithInt:0],DIC_EXPANDED,nil];
        // 将字典加入数组
        [self.dataArray addObject:dic];
    }
    
    [db close];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSMutableDictionary *dic=[_dataArray objectAtIndex:section];
    NSArray *array=[dic objectForKey:DIC_ARARRY];
    //判断是收缩还是展开
    if ([[dic objectForKey:DIC_EXPANDED]intValue]) {
        return array.count;
    }else{
        return 0;
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    long section=indexPath.section;
    long row=indexPath.row;
    //得到改组下信息
    NSMutableDictionary *dic=[self.dataArray objectAtIndex:section];
    NSArray *array=[dic objectForKey:DIC_ARARRY];
    NSDictionary *data=array[row];
    
    //判断类型
    if([data[@"type"]isEqualToString:@"RECORD_01"]||[data[@"type"]isEqualToString:@"RECORD_03"]||[data[@"type"]isEqualToString:@"RECORD_04"]||[data[@"type"]isEqualToString:@"RECORD_07"]||[data[@"type"]isEqualToString:@"RECORD_08"]||[data[@"type"]isEqualToString:@"RECORD_09"]||[data[@"type"]isEqualToString:@"RECORD_10"]||[data[@"type"]isEqualToString:@"RECORD_11"]||[data[@"type"]isEqualToString:@"RECORD_12"]||[data[@"type"]isEqualToString:@"RECORD_13"]||[data[@"type"]isEqualToString:@"RECORD_14"]){
        
        JLJLTableCell *cell=[tableView dequeueReusableCellWithIdentifier:@"JLJLCell" forIndexPath:indexPath];
  
        NSString *recordType=data[@"type"];
        cell.recordType=recordType;
               
        NSString *titles=data[@"title"];
        if(!titles){
            titles=@"无";
        }
        cell.title.text=[titles isEqualToString:@""]?@"无":titles;
        
        cell.address.text=data[@"address"];
        
        cell.name.text=data[@"recordName"];
        
        cell.time.text=data[@"time"];
        
        return cell;

    }else{
        
        RJTableCell *cell=[tableView dequeueReusableCellWithIdentifier:@"RJCell" forIndexPath:indexPath];
        cell.title.text=data[@"title"];
        
        cell.type=data[@"type"];

        cell.time.text=data[@"time"];
        
        cell.name.text=data[@"recordName"];
        
        cell.state.hidden=YES;
        
        return cell;
        
    }
    
}


//设置分组头的视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *hView = [[UIView alloc]initWithFrame:CGRectMake(0,0, DEF_SCREEN_WIDTH,(CELL_HEIGHT-5)*BIZ)];
    hView.backgroundColor=[UIColor colorWithRed:0.94 green:0.94 blue:0.94 alpha:1.00];
    UIButton* eButton = [[UIButton alloc] init];
    eButton.backgroundColor=[UIColor whiteColor];
    //按钮填充整个视图
    eButton.frame = hView.frame;
    [eButton addTarget:self action:@selector(expandButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    //把节号保存到按钮tag，以便传递到expandButtonClicked方法
    eButton.tag = section;
    //根据是否展开，切换按钮显示图片
    if ([self isExpanded:section])
        [eButton setImage:  [UIImage imageNamed: @"xiala" ]forState:UIControlStateNormal];
    else
        [eButton setImage: [UIImage imageNamed: @"gengduo1" ]forState:UIControlStateNormal];
    
    //设置分组标题
    [eButton setTitle:[[self.dataArray objectAtIndex:section] objectForKey:DIC_TITILESTRING]forState:UIControlStateNormal];
    
    [eButton setTitleColor:[UIColor colorWithRed:0.68 green:0.68 blue:0.68 alpha:1.00] forState:UIControlStateNormal];
    //设置字体样式
    eButton.titleLabel.font=[UIFont systemFontOfSize:16.*BIZ];
    
    //设置button的图片和标题的相对位置
    
    //4个参数是到上边界，左边界，下边界，右边界的距离
    eButton.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;
    UIImage *image=eButton.imageView.image;
    [eButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, image.size.width)];
    [eButton setImageEdgeInsets:UIEdgeInsetsMake(0, eButton.titleLabel.bounds.size.width+20, 0, -eButton.titleLabel.bounds.size.width)];
    
    //添加btn
    [hView addSubview: eButton];
    return hView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    //判断是收缩还是展开
    NSMutableDictionary *dic=[self.dataArray objectAtIndex:section];
    if ([[dic objectForKey:DIC_EXPANDED]intValue]) {
        return 5;
    }else{
        return 0.1;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60*BIZ;
}

//控制表头分组表头高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 46*BIZ;
}
#pragma mark-点击表格
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    long section=indexPath.section;
    long row=indexPath.row;
    //得到改组下信息
    NSMutableDictionary *dic=[self.dataArray objectAtIndex:section];
    NSArray *array=[dic objectForKey:DIC_ARARRY];
    NSDictionary *data=array[row];
    
    NSString *type=data[@"type"];
    NSString *recordId=data[@"recordId"];
    BOOL edit=[USERID isEqualToString:recordId];
    BOOL riji=[LSUtility isSameDay:data[@"times"] andRecordId:data[@"id"]];
    
    //判断类型
    if([type isEqualToString:@"RECORD_01"]||[type isEqualToString:@"RECORD_03"]||[type isEqualToString:@"RECORD_04"]||[data[@"type"]isEqualToString:@"RECORD_07"]||[data[@"type"]isEqualToString:@"RECORD_08"]||[data[@"type"]isEqualToString:@"RECORD_09"]||[data[@"type"]isEqualToString:@"RECORD_10"]||[data[@"type"]isEqualToString:@"RECORD_11"]||[data[@"type"]isEqualToString:@"RECORD_12"]||[data[@"type"]isEqualToString:@"RECORD_13"]||[data[@"type"]isEqualToString:@"RECORD_14"]){
        JLAddJLViewController *JLCtr=[[JLAddJLViewController alloc]init];
        JLCtr.recordId=data[@"id"];
        
        JLCtr.isEdit=edit&&riji;
        [self.navigationController pushViewController:JLCtr animated:YES];
    
    }else{
        if([type isEqualToString:@"RECORD_02_01"])
        {
            TYPZViewController *pzCtr=[[TYPZViewController alloc]init];
            if(!edit){
                pzCtr.flag=@"look";
            }
            pzCtr.isSubStr=@"flag";
            pzCtr.sideId=data[@"id"];
            [self.navigationController pushViewController:pzCtr animated:YES];
            
        }
        else if ([type isEqualToString:@"RECORD_02_02"])
        {
            FSSGViewController *pzCtr=[[FSSGViewController alloc]init];
            pzCtr.isSubStr=@"flag";
            if(!edit){
                pzCtr.flag=@"look";
            }
            pzCtr.sideId=data[@"id"];
            [self.navigationController pushViewController:pzCtr animated:YES];
        }
        else if ([type isEqualToString:@"RECORD_02_03"])
        {
            HTTViewController *pzCtr=[[HTTViewController alloc]init];
            pzCtr.sideId=data[@"id"];
            pzCtr.isSubStr=@"flag";
            if(!edit){
                pzCtr.flag=@"look";
            }
            [self.navigationController pushViewController:pzCtr animated:YES];
        }
        else if ([type isEqualToString:@"RECORD_02_04"])
        {
            HNTViewController *pzCtr=[[HNTViewController alloc]init];
            pzCtr.isSubStr=@"flag";
            if(!edit){
                pzCtr.flag=@"look";
            }
            pzCtr.sideId=data[@"id"];
            [self.navigationController pushViewController:pzCtr animated:YES];
        }
        else if ([type isEqualToString:@"RECORD_02_05"])
        {
            GZZViewController *pzCtr=[[GZZViewController alloc]init];
            pzCtr.sideId=data[@"id"];
            if(!edit){
                pzCtr.flag=@"look";
            }
            pzCtr.isSubStr=@"flag";
            [self.navigationController pushViewController:pzCtr animated:YES];
        }else{
            
            JJTYPZViewController *jjtyCtr = [[JJTYPZViewController alloc]init];
            NSString *titleStr = @"";
            if ([type isEqualToString:@"RECORD_02_JJ_01"]) {
                titleStr = @"通用";
                
            } else if ([type isEqualToString:@"RECORD_02_JJ_02"]) {
                titleStr = @"桩基钢筋笼安放";
                
            } else if ([type isEqualToString:@"RECORD_02_JJ_03"]) {
                titleStr = @"灌注桩首盘砼浇筑";
                
            } else if ([type isEqualToString:@"RECORD_02_JJ_04"]) {
                titleStr = @"路面(沥青)混凝土摊铺";
                
            } else if ([type isEqualToString:@"RECORD_02_JJ_05"]) {
                titleStr = @"预应力张拉";
                
            } else if ([type isEqualToString:@"RECORD_02_JJ_06"]) {
                titleStr = @"预应力压浆";
            }
            jjtyCtr.title = titleStr;
            jjtyCtr.isSubStr= type;
            jjtyCtr.sideId = data[@"id"];
            
            if(!edit){
                jjtyCtr.flag = @"look";
            }
            [self.navigationController pushViewController:jjtyCtr animated:YES];
        }
    }
}

#pragma mark-methold

- (void)clickCan{

    [UIView animateWithDuration:0.4 animations:^{
        
        _listView.frame =CGRectMake(DEF_SCREEN_WIDTH, 0,  DEF_SCREEN_WIDTH*0.85, DEF_SCREEN_HEIGHT);

    }];
}


- (void)clickSure
{
//    NSString *str
    NSLog(@"确定选择%@",self.seleceArr);
    [self refresh:nil];

//    if(self.seleceArr.count>0){
//        [self refresh:nil];
//    }
    
    [UIView animateWithDuration:0.4 animations:^{
        _listView.frame =CGRectMake(DEF_SCREEN_WIDTH, 0,  DEF_SCREEN_WIDTH*0.85, DEF_SCREEN_HEIGHT);
    }];
}



#pragma mark-UICollectionDataSoure
//返回组
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

//返回每组个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    //项目人员数
    return self.btnArray.count;
    
}

//返回内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    btnCollCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
    
    NSDictionary *userDic=[self.btnArray objectAtIndex:indexPath.row];
    
    //设置title
    [cell setCollBtnTitle:[userDic objectForKey:@"name"] andId:[userDic objectForKey:@"id"]];
    
    //点击事件
    cell.clickBtnBlock=^(NSString *title){
        //判断选项数组中是否存在就移除掉
        if ([self.seleceArr containsObject:title]) {
            [self.seleceArr removeObject:title];
        }else {//添加选项
            [self.seleceArr addObject:title];
        }
    };
    return cell;
}

//返回头视图
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    UICollectionReusableView *reusableview = nil;
    if (kind == UICollectionElementKindSectionHeader){
        SXheadView *header = (SXheadView *)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headView" forIndexPath:indexPath];
        header.titleLab.text=@"人员选择";
        reusableview = header;
    }
    return reusableview;
    
}

#pragma mark -- 内部调用

//对指定的节进行“展开/折叠”操作,若原来是折叠的则展开，若原来是展开的则折叠
-(void)collapseOrExpand:(long)section{
    NSMutableDictionary *dic=[_dataArray objectAtIndex:section];
    int expanded=[[dic objectForKey:DIC_EXPANDED] intValue];
    if (expanded) {
        [dic setValue:[NSNumber numberWithInt:0]forKey:DIC_EXPANDED];
    }else
    {
        [dic setValue:[NSNumber numberWithInt:1]forKey:DIC_EXPANDED];
    }
    
}

//返回指定节是否是展开的

-(int)isExpanded:(long)section{
    NSDictionary *dic=[_dataArray objectAtIndex:section];
    int expanded=[[dic objectForKey:DIC_EXPANDED] intValue];
    return expanded;
}

//按钮被点击时触发
-(void)expandButtonClicked:(id)sender{
    //隐藏侧滑栏
    [UIView animateWithDuration:0.4 animations:^{
        _listView.frame =CGRectMake(DEF_SCREEN_WIDTH, 0,  DEF_SCREEN_WIDTH*0.85, DEF_SCREEN_HEIGHT);
    }];
    UIButton* btn= (UIButton*)sender;
    long section= btn.tag;//取得tag知道点击对应哪个块
    [self collapseOrExpand:section];
    //刷新tableview
    [self.tableView reloadData];
}

- (void)viewDidDisappear:(BOOL)animated{
    [UIView animateWithDuration:0.4 animations:^{
        _listView.frame =CGRectMake(DEF_SCREEN_WIDTH, 0,  DEF_SCREEN_WIDTH*0.85, DEF_SCREEN_HEIGHT);
    }];
}

#pragma mark scrollview
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    [UIView animateWithDuration:0.4 animations:^{
        _listView.frame =CGRectMake(DEF_SCREEN_WIDTH, 0,  DEF_SCREEN_WIDTH*0.85, DEF_SCREEN_HEIGHT);
    }];
}
-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


@end
